import { Controller, Get, Request, Post, UseGuards, Body, Delete, Query, Put, Param, ParseIntPipe } from "@nestjs/common";
import { UsersEntity } from "src/Entity/user.entity";
import { MyApi } from "../action/descriptor/function.descriptoor";
import { MyController } from "../action/descriptor/http.decorator";
import { AuthService } from "./auth.service";
import { JwtAuthGuard } from "./guard/jwt-auth.guard";
import { LocalAuthGuard } from "./guard/local-auth.guard";


@Controller('/auth')
@MyController('AuthController')
export class AuthController {
    constructor(private authService: AuthService) { }

    @UseGuards(LocalAuthGuard)
    @Post('/login')
    @MyApi("登录")
    async login(@Body() usersEntity: UsersEntity) {
        // console.log(req);
        return this.authService.login(usersEntity);
    }

    @UseGuards(JwtAuthGuard)
    @Get('profile')
    getProfile(@Request() req) {
        // console.log(req.user.userId);
        return req.user;
    }

    // @UseGuards(JwtAuthGuard)
    // @Post()
    // addUser(@Body() usersEntity: UsersEntity) {
    //     return this.authService.addUser(usersEntity);
    // }

    // @UseGuards(JwtAuthGuard)
    // @Get()
    // async findAll(): Promise<UsersEntity[]> {
    //     return this.authService.findAll();
    // }

    // @Get('/username/:username')
    // async findOne(@Param('username') usernmae: string): Promise<UsersEntity> {
    //     return this.authService.findOne(usernmae);
    // }

    // @UseGuards(JwtAuthGuard)
    // @Delete(':id')
    // @ApiQuery({
    //     name: 'userId',
    //     description: '用户id'
    // })
    // async deleteById(@Param('id', ParseIntPipe) id: number) {
    //     return this.authService.deleteById(id);
    // }

    // @UseGuards(JwtAuthGuard)
    // @Put()
    // async updateUser(@Body() usersEntity: UsersEntity) {
    //     return this.authService.updateUser(usersEntity);
    // }

}


